package com.sun.stringescapeutils;

import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

import java.time.LocalTime;

public class MonoDemo {
    public static void main(String[] args) {
        //方式1
        Mono<Integer> just = Mono.just(1);
        blockMono("just", just);
        //方式2
        Mono<String> stringMono = Mono.fromCallable(() -> Thread.currentThread().getName() + "@" + LocalTime.now())
                .publishOn(Schedulers.boundedElastic());//在哪个线程池中跑

        blockMono("stringMono", stringMono);
    }

    private static void blockMono(String varName, Mono mono) {
        mono.doOnSubscribe(s -> System.out.print(varName + ":"))
                .doOnNext(e -> System.out.print(e + "\n"))
                .block();//当所有的流处理完成了才会返回到下一步
    }
}
